package test.n00300;


import static utils.Tools.listOf;

public class Problem00350 {
    public static void main(String[] args) {
        //println(new int[]{1, 3, 5, 6}, 5);
        //println(new int[]{1, 3, 5, 6}, 2);
        println(new int[]{1, 3, 5, 6}, 7);
    }

    public static void println(int[] nums, int target) {
        Solution ss = new Solution();
        System.out.println(listOf(nums) + "," + target + "," + listOf(ss.searchInsert(nums, target)));
    }

    private static class Solution {
        public int searchInsert(int[] nums, int target) {
            int left = 0, right = nums.length - 1;

            int r = nums.length;
            while (left <= right) {
                int mid = left + ((right - left) >> 1);
                if (target <= nums[mid]) {
                    right = mid - 1;
                    r = mid;
                } else {
                    left = mid + 1;
                }
            }
            return r;
        }
    }
}
